package com.cubeofnine.sugar.activity.export_contact;

import com.cubeofnine.android.api.ContactAPI;
import com.cubeofnine.android.api.contact.ContactList;

import android.content.ContentResolver;
import android.content.Context;
import android.os.Handler;
import android.util.Log;

public class ExportContactsListThread extends Thread {
	private Context context;
	private Handler handler = new Handler();

	public ExportContactsListThread(Context context) {
		super();
		this.context = context;
	}

	public String getClassName() {
		return ExportContactsListThread.class.getName();
	}

	public void run() {
		Log.i(getClassName(), "run() : Start");

		ContactList contactList = null;
		String message = "";
		try {
			ContentResolver cr = context.getContentResolver();
			ContactAPI api = new ContactAPI();
			api.setCr(cr);
			contactList = api.newContactList();
		} catch (Exception e) {
			Log.e(getClassName(), "Error", e);
			message = "Read Contacts Error.";
		} finally {
			Log.d(getClassName(), "Finally");
			handler.post(new ExportContactsListRunnable(context, contactList,
					message));
		}

		Log.i(getClassName(), "run() : End");
	}
}
